#include "logger.h"
#include "consolechannel.h"
#include "filechannel.h"
#include <iostream>
#include <unistd.h>

using namespace std;

string logfile("test");

//#define trace(fmt,...) log_trace(gLog,fmt,__VA_ARGS__)
// 上面这种写法处理不了 trace("aaaa") 这种形式
#define trace(fmt,args...) log_trace(gLog,fmt,##args)
#define debug(fmt,args...) log_debug(gLog,fmt,##args)
#define info(fmt,args...) log_info(gLog,fmt,##args)
#define warning(fmt,args...) log_warning(gLog,fmt,##args)
#define error(fmt,args...) log_error(gLog,fmt,##args)
#define fatal(fmt,args...) log_fatal(gLog,fmt,##args)

int main(int argc, char** argv)
{
    Logger* gLog = new Logger("main","debug");

    // add filechannel
    FileChannel* pfc = new FileChannel(logfile);
    pfc->setRotateSize("1M");
    pfc->setRotateTime("1H");

    gLog->addChannel(pfc);
    
    // add consolechannel

    ConsoleChannel* pcc = new ConsoleChannel();
    gLog->addChannel(pcc);

    string msg(10,'a');

    while(1)
    {
        //trace("%s",msg.c_str());
        trace("aaaaaaaa");
        debug("aaaaaaa");
        info("%s",msg.c_str());
        //warning("%s",msg.c_str());
        //error("%s",msg.c_str());
        //fatal("%s",msg.c_str());

        sleep(1);
    }
    
    return 0;
}
    


    
    
    
    
    
    
    
    
    
    
    
    
